<template>
	<view class="content">
		<template v-if="list.length>0">
			<view class="info-list" v-for="(item,index) in list" :key="item.id"
				@click="navigate('/page_other/job_hunting/intermediary/detail?id='+item.id)">
				<image :src="item.logo?item.logo:imageUrl+'/job_hunting/job_detail/enterprise.jpg'"
					class="company-photo">
				</image>
				<view class="info-item">
					<view class="name">{{item.name}}</view>
					<view class="address-item">
						<i class="iconfont icon-dingwei"></i>
						<view class="address">{{item.address}}</view>
					</view>
				</view>
			</view>
		</template>
		<view v-if="list.length==total&&!more" style="text-align: center;">没有更多了哦</view>
		<view v-else style="text-align: center;">暂无数据</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import {
		getIntermediaryList
	} from '@/api/job_hunting.js'
	export default {
		data() {
			return {
				imageUrl: '',
				page: 1,
				limit: 10,
				more: true,
				total: 0,
				list: []
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			refresh() {
				this.page = 1
				this.more = true
				this.getList(true);
			},
			getList(refresh = false) {
				getIntermediaryList({
					page: this.page,
					limit: this.limit
				}).then((res) => {
					let list = res.list ?? [];
					this.list = refresh ? list : [...this.list, ...list],
						this.total = res.count
					this.more = isMore(this.page, this.limit, this.total)
				})
			}
		},
		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
		onLoad() {
			this.imageUrl = this.globalConfig.imageUrl;
			this.getList(true);
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F7F6F9;
	}

	.content {
		padding: 30rpx;

		.info-list {
			background-color: #fff;
			border-radius: 30rpx;
			padding: 30rpx;
			display: flex;
			margin-bottom: 30rpx;

			.company-photo {
				width: 150rpx;
				height: 150rpx;
				margin-right: 30rpx;
				border-radius: 20rpx;
				background-color: #F7F6F9;
			}

			.info-item {
				width: calc(100% - 180rpx);
				display: flex;
				flex-direction: column;
				justify-content: center;

				.name {
					margin-bottom: 30rpx;
				}

				.address-item {
					display: flex;
					align-items: center;

					.iconfont {
						color: #0256FF;
						margin-right: 10rpx;
					}

					.address {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						color: #999;
						font-size: 26rpx;
					}
				}
			}
		}
	}
</style>